package com.greate.community.controller.master;

import com.greate.community.entity.Permission;
import com.greate.community.service.master.RBACService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionAdminController {

    @Autowired
    private RBACService rbacService;

    @RequestMapping("/getPermission")
    public List<Permission> getPermission(){
        return rbacService.getAllPermission();
    }

    /**
     * 添加权限
     * @param permission
     * @return
     */
    @RequestMapping(value = "/addPermission",method = RequestMethod.POST)
    public String addPermission(@RequestBody Permission permission){
        return rbacService.addPermission(permission);
    }

    /**
     * 更新权限
     * @param permission
     * @return
     */
    @RequestMapping(value ="/updatePermission",method = RequestMethod.POST)
    public String updatePermission(@RequestBody Permission permission){
        return rbacService.updatePermission(permission);
    }

    /**
     * 删除权限
     * @param permissionId
     * @return
     */
    @RequestMapping("/deletePermission")
    public String deletePermission(int permissionId){
        return rbacService.deletePermission(permissionId);
    }
}
